<template>
    <Card>
        <JG-search :searchData="searchData" @on-input-search="askDatasearch" @on-change-search="askDatasearchs" @on-change-change="askDatas" />
        <JG-table :params="params" :loading="loading" :total="total"
                    @askData="askData" :data="data" :columns="columns" @handleDetails="handleDetails"></JG-table>
    </Card>
</template>
<script>
    import { siteindexyhloglist } from '@api/kingpush'
    export default {
        name: '',
        data () {
            return {
                modal: false,
                params: { domain: '', type: '', operate_id: '', page: 1, pageSize: 10 },
                loading: false,
                total: 0,
                searchData: {
                    left: [
                        { id: 1, key: 'Input', value: '', clearable: true, placeholder: '请输入域名信息', callback: 'search' },
                        { id: 2,
                          key: 'Select',
                          value: '',
                          clearable: true,
                          placeholder: '请选择收录方式',
                          childList: [
                              { value: '1', label: '快速收录' }, { value: '2', label: '普通收录' }
                          ],
                          callback: 'change' },
                        { id: 3, key: 'Select', value: '', clearable: true, placeholder: '请选择操作人', childList: [], callback: 'change' }
                    ]
                },
                columns: [
                    { title: '域名', key: 'domain', minWidth: 120 },
                    { title: '推送时间', key: 'created_at_str', width: 170 },
                    { title: '推送方式', key: 'type_str', width: 160 },
                    { title: '操作人', key: 'operate_name', width: 80 },
                    { title: '用户IP', key: 'operate_ip', width: 160 },
                    { title: '操作', slot: 'kingpushAction', width: 80 }
                ],
                data: []
            }
        },
        mounted () {
            this.initial()
        },
        methods: {
            initial () {
                this.askData()
            },
            askDatas () {
                this.params.page = 1
                this.askData()
            },
            askDatasearchs () {
                this.searchData.left.forEach((item) => {
                    if (item.id === 1) {
                        item.value = ((item.value.replace(/(^\s*)|(\s*$)/g, '')).replace(/(^\http:\/\/*)|(\/*$)/g, '')).replace(/(^\https:\/\/*)|(\/*$)/g, '')
                    }
                });
                this.askDatasearch()
            },
            askData () {
                this.searchData.left.forEach((item) => {
                    if (item.id === 1) {
                        this.params.domain = item.value
                    } else if (item.id === 2) {
                        this.params.type = item.value
                    } else if (item.id === 3) {
                        this.params.operate_id = item.value
                    }
                });
                this.loading = true
                siteindexyhloglist(this.params).then(res => {
                    this.total = res.total
                    this.data = res.list
                    this.searchData.left.forEach((item) => {
                        if (item.id === 3) {
                            if (JSON.stringify(item.childList) == '[]') {
                                item.childList = res.condition.member_list
                            }
                        }
                    });
                    this.loading = false
                }).catch(() => {
                    this.loading = false;
                });
            },
            askDatasearch () {
                this.params.page = 1
                this.searchData.left.forEach((item) => {
                    if (item.id === 2) {
                        item.value = '';
                    } else if (item.id === 3) {
                        item.value = '';
                    }
                });
                this.askData()
            },
            handleDetails (row) {
                let url = ''
                for (let item of row.push_url) {
                    url += `<p class='ivu-mt-8'>${item}</p>`
                    // url+=`<p class='ivu-mt-8'>${item}</p>`
                }
                this.$Modal.info({
                    scrollable: true,
                    width: '600px',
                    title: '详情',
                    content: `<h3>域名：${row.domain}</h3><p class='ivu-mt-8'>推送URL详情：</p><div style="max-height: 300px; overflow: auto">${url}</div>`
                });
                this.log(row.domain, row.push_url)
            }
        }
    }
</script>
